#include "StdAfx.h"
#include "OneSvrThread.h"
#include "MainFrm.h"

COneSvrThread::COneSvrThread(void)
{
	m_nFrameNum = 0;
	m_nCurQuest = -1;
	m_nPreQuest = -1;
}

COneSvrThread::~COneSvrThread(void)
{

}
void	COneSvrThread::OnRequestHF1(unsigned char * pdata, int nsize)
{

	m_nCurQuest = 1;
	CMainFrame* pfrm = (CMainFrame*)::AfxGetMainWnd();

	/*if( pfrm->GetDDfFile()->GetFrameDataFromPos( m_nFrameNum, &m_CurFrame ) )
	{
		//memset( m_CurFrame.data , 100, 24576 );
		memcpy( pdata, (char*)&m_CurFrame, 256 );
		memcpy( pdata + 256,  m_CurFrame.data, 24576 );
	
	}	*/
	
	if(  m_nCurQuest != m_nPreQuest )
	{
		CDDsServerThread::OnRequestHF1( pdata, nsize );
		//TRACE("\nhf1\n");
	}

	m_nPreQuest = m_nCurQuest;
	
}


void COneSvrThread::OnRequestHF2(unsigned char * pdata, int nsize)
{
	//memset( m_CurFrame.data + nsize, 255, nsize );
	m_nCurQuest = 2;

	//if( ( m_nCurQuest != m_nPreQuest && !m_bLongRange ) || m_bLongRange)
	{
		
		
	}
	
	if(  m_nCurQuest != m_nPreQuest )
	{
		
	
	m_nFrameNum++;	
	memcpy( pdata, (char*)( m_CurFrame.data + 24576) , 24576); 
	CDDsServerThread::OnRequestHF2( pdata, nsize );
		//TRACE("\nhf2\n");
	//}
	}
	m_nPreQuest = m_nCurQuest;

	
}
void COneSvrThread::OnRequestHL(unsigned char * pdata, int nsize)
{
	
	CMainFrame* pfrm = (CMainFrame*)::AfxGetMainWnd();

	/*if( pfrm->GetDDfFile()->GetFrameDataFromPos( m_nFrameNum, &m_CurFrame ) )
	{
		//memcpy( pdata, (char*)&m_CurFrame, nsize); 

		memcpy( pdata, (char*)&m_CurFrame, 256 );
		memcpy( pdata + 256,  m_CurFrame.data, 24576 );
	}*/
	m_nFrameNum++;
	if( m_nFrameNum >=  pfrm->GetDdsFilePtr()->GetFrameSum() )
	{
		m_nFrameNum = 0;
	}
	
	CDDsServerThread::OnRequestHL( pdata, nsize );
}
void COneSvrThread::OnRequestHD(unsigned char * pdata, int nsize)
{
	CMainFrame* pfrm = (CMainFrame*)::AfxGetMainWnd();

	if( pfrm->GetDdsFilePtr()->GetDDFHeaderData( &m_CurHeader) )
	{
		memcpy( pdata, (char*)&m_CurHeader, nsize); 

	}

	TRACE("COneDDsSvrThread::OnRequestHD");
	CDDsServerThread::OnRequestHD( pdata, nsize );
}

void COneSvrThread::OnRequestNetInfo( unsigned char * pdata, int nsize )
{
	CMainFrame* pfrm = (CMainFrame*)::AfxGetMainWnd();
	dds::DidsonSysParam sysparam;
	memcpy( (char*)&sysparam,pdata , nsize );
	if( pfrm != NULL )
	{
		dds::DidsonSysParam sysparam;
		pfrm->GetSonarIniFile()->ToParaStruct( sysparam );
		memcpy( pdata, (char*)&sysparam, nsize );

	}CDDsServerThread::OnRequestNetInfo( pdata, nsize );/**/
	TRACE("COneSvrThread::OnRequestNetInfo");	
	
}

void COneSvrThread::OnSetCommand(  unsigned char* pCommList, int nCmdsize )
{
	int ndwSum = nCmdsize/4;
	//DWORD * pbuf = new DWORD[ndwSum];
	DWORD  pbuf[68]; 
	memcpy( pbuf , pCommList,nCmdsize);

	for( int i= 0; i<33; i++  )
	{
	
		if(  pbuf[i] == (i+ 0x695a0000))
		{
			TRACE(" 0x%x, %d\n", i, pbuf[35+i] );	

		}

	}
	//delete[] pbuf;


}